package com.ymatou.iapi.trading.userquery.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.userquery.parameter.GetConsultingOrderInfoReq;
import com.ymatou.iapi.trading.userquery.service.GetConsultingOrderInfoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.YMTDateUtil;

/**
 * 获取待咨询订单
 */
@TestSuite
public class Ts_GetConsultingOrderInfo {

	private static GetConsultingOrderInfoReq req;
	private static GetConsultingOrderInfoCall getConsultingOrderInfoCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取买家订单列表");
	}

	@Before
	public void caseUp() {
		req = new GetConsultingOrderInfoReq();
		getConsultingOrderInfoCall = new GetConsultingOrderInfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getConsultingOrderInfoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	/*	public void constructExpectResponse(GetBuyerOrderInfoV2Resp resp) {
			OrderQueryWapper orderQuery = new OrderQueryWapper();
			Order order = orderQuery.findById(req.getOrderId());
			ConvertUtils.convertBigDecimal(order);
			if (order != null && order.getUserId().equals(req.getUserId())) {
				resp.setOrderInfo(OrderInfoBuilder.convertFromOrder(order, true));
			}
		}

		private void verify() {
			GetBuyerOrderInfoV2Resp expectResponse = new GetBuyerOrderInfoV2Resp();
			constructExpectResponse(expectResponse);
			GetBuyerOrderInfoV2Resp actualResponse = getConsultingOrderInfoCall
					.getBuyerOrderInfoResponseV2();

			OrderInfo expect = expectResponse.getOrderInfo();
			OrderInfo actual = actualResponse.getOrderInfo();
			expect.verify(actual);
			if (actual != null) {
				BargainGroupInfo act = actual.getBargainGroup();
				BargainGroupInfo exp = new Ts_GetBuyerOrderInfosV2()
						.getBargainGroupInfoFromMssql((int) expect.getOrderId());
				if (exp == null) {
					DataUtil.verify(
							null,
							act,
							String.format(
									"验证 sqlserver中订单id:%d 没有参加砍价团(orderInfos.bargainGroup == null)",
									expect.getOrderId()));
				} else {
					DataUtil.verifyObject(exp, act, "砍价团信息orderInfos.bargainGroup");
				}
			}
		}
	*/
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetConsultingOrderInfo_001() {
		Logger.start(true, "获取待咨询订单,只传userid,ordernum，倒序排列,查询成功");
		try {

			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId2"));

			req.setUserId(userId);
			//req.setSellerId(sellerId);
			req.setOrderNum(100);

			getConsultingOrderInfoCall.setData(req);
			getConsultingOrderInfoCall.callService();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetConsultingOrderInfo_002() {
		Logger.start(true, "获取待咨询订单, 参数全传，查询成功");
		try {

			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));

			req.setUserId(userId);
			req.setSellerId(sellerId);
			req.setBeginTime(YMTDateUtil.getBeforeOrNextDay(-10,
					YMTDateUtil.YMDTHMS_STRING));
			req.setEndTime(YMTDateUtil.getBeforeOrNextDay(1,
					YMTDateUtil.YMDTHMS_STRING));
			req.setOrderNum(10);

			getConsultingOrderInfoCall.setData(req);
			getConsultingOrderInfoCall.callService();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetConsultingOrderInfo_009() {
		Logger.start(true, "买家用户id为null");
		try {

			getConsultingOrderInfoCall.setData(req);
			getConsultingOrderInfoCall.callService();

			DataUtil.verify(400, getConsultingOrderInfoCall.getCode(), "验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetConsultingOrderInfo_010() {
		Logger.start(true, "orderNum为null");
		try {

			req.setUserId(1);
			getConsultingOrderInfoCall.setData(req);
			getConsultingOrderInfoCall.callService();

			DataUtil.verify(400, getConsultingOrderInfoCall.getCode(), "验证Code");

			Logger.verifyEquals("100",
					getConsultingOrderInfoCall.getString("bcode"), "验证bcode");

			Logger.verifyEquals("orderNum:orderNum未提供",
					getConsultingOrderInfoCall.getMsg(), "验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}